#include "MemoryPoolTest.h"
#include "CBL_PooledObject.h"

class CTestObject1 : public CB_SNS(Memory)::CPooledObject
{
public:
	CTestObject1() : m_Init1(0xFF00FF00) {}
	
	int m_Init1;
};

class CTestObject2 : public CTestObject1
{
public:
	CTestObject2() : m_Init2(0xFFAAFFAA) {}
	
	int m_Init2;
};

class CTestObject3 : public CB_SNS(Memory)::CPooledObject
{
public:
	virtual ~CTestObject3() { m_Init = 0xAAFFAA00; }
	
	int m_Init;
};

BEGIN_TEST_CASE_IMPLEMENTATION(CMemoryPoolTest)

	CTestObject1* pT1 = new CTestObject1();
	CTestObject2* pT2 = new CTestObject2();
	CTestObject3* pT3 = new CTestObject3();

	unsigned int Offset1 = (unsigned int)pT2 - (unsigned int)pT1;
	unsigned int Offset2 = (unsigned int)pT3 - (unsigned int)pT1;

	CHECK(pT1->m_Init1 == 0xFF00FF00,		"> Pooled object new test failed.")
	CHECK(pT2->m_Init1 == 0xFF00FF00,		"> Pooled object Baseclass test failed.")
	CHECK(Offset1 > sizeof(CTestObject1),	"> Pooled object different pool size test failed.")
	CHECK(pT2->m_Init2 == 0xFFAAFFAA,		"> Pooled object derived test failed.")
	CHECK(Offset2 == sizeof(CTestObject1),	"> Pooled object same pool size test failed.")

	delete pT3;
	delete pT1;
	delete pT2;
	
	CHECK(pT3->m_Init == 0xAAFFAA00,		"> Pooled object delete test failed.")
	
	pT3 = new CTestObject3(); // pT1 has the same size and is first in list now

	CHECK(pT3->m_Init == 0xFF00FF00,		"> Pooled object re-use test failed.")

	delete pT3;

END_TEST_CASE_IMPLEMENTATION